package org.feluma.sgci.util;

import java.sql.*;
import org.feluma.sgci.util.Excecao;

public class Conexao{
	
	private static int sistema;
	public static Connection getConexaoMssql() throws Excecao{
		try{
			Class.forName("net.sourceforge.jtds.jdbc.Driver");
			//return DriverManager.getConnection("jdbc:jtds:sqlserver://localhost/geral", "sa", "analaura");
			return DriverManager.getConnection("jdbc:jtds:sqlserver://192.168.0.16/geral", "sa", "@sql08#$");
		}catch (Exception e) { 
			e.printStackTrace();
			throw new Excecao(e.getMessage());
		}
	}

	public static void closeConnection(Connection conn,Statement stmt, ResultSet rs) throws Excecao{
       close(conn,stmt,rs);
    }
    
    public static void closeConnection(Connection conn,Statement stmt)throws Excecao{
        close(conn,stmt,null);
    }

    public static void closeConnection(Connection conn)throws Excecao{
        close(conn,null,null);
    }
    
    private static void close(Connection conn, Statement stmt, ResultSet rs)throws Excecao{
        try{
            if(conn != null) conn.close();
            if(stmt != null) stmt.close();
            if(rs != null) rs.close();
        }
        catch(Exception e){
            throw new Excecao(e.getMessage());
        }
    }
}
